<?php

namespace app\admin\model\activity;

use think\Model;
use think\Db;
use app\admin\model\activity\Ranklist;

class Activitylist extends Model
{
    // 表名
    protected $name = 'events_guess';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'winner_team_text'
    ];


    public function getWinnerTeamTextAttr($value, $data)
    {
        $lists = Db::name('event_guess_teams')
            ->whereIn('id', $data['winner_team_id'])
            ->column('name');
        return implode(',', $lists);
    }

    
    public function activity(){
        $activitys = Db::name('event_guess_teams')->order('id desc')->select();
        // echo "<pre>";
        // print_r($activitys);die;
        return $activitys;
    }

   //礼券列表
    public function coupon(){
        $couponlist = Db::name('shopro_coupon')->order('id desc')->select();
        return $couponlist;
    }

    public function ranklist()

    {
        return $this->belongsTo('\app\admin\model\activity\Rankslist', 'winner_team_id', 'id', [], 'LEFT')->setEagerlyType(0);

    }
    







}
